<template>
	<view class="send">
		<view class="public-nav">
			<view class="public-nav-fixed">
				<view class="public-nav-top" style="background-color: #FFF;color: #333;">
					<view class="public-nav-top-status-bar" :style="{ height: systemInfo.statusBarHeight + 'px' }">
					</view>
					<view v-if="platform==false" class="public-nav-top-navbar-inner"
						:style="{ height: navHeight + 'px', lineHeight:navHeight+'px' }">
						<text></text>
						<view></view>
					</view>
				</view>
				<view class="send-nav-search" :style="{ height: optionHeight + 'px', lineHeight:optionHeight+'px' }">
					<view class="send-nav-search-left-btn" @click="returnclick">
						<text class="iconfont iconarrow_left-copy"></text>
					</view>
					<view class="send-nav-search-ipt">
						<text class="iconfont iconsousuo"></text>
						<input type="text" v-model="erpkeyword" @input="erpIpt" value="" placeholder="请输入企业名称" />
					</view>
					<view class="send-nav-search-btn" @click="erpIpt">
						搜索
					</view>
				</view>
			</view>
			<view v-if="platform==false" class="public-nav-placeholder"
				:style="{ height: Number(optionHeight)+  Number(navHeight)  +Number(systemInfo.statusBarHeight)+ 'px' }">
			</view>
			<view v-else class="public-nav-placeholder"
				:style="{ height: Number(optionHeight) +Number(systemInfo.statusBarHeight)+ 'px' }">
			</view>
		</view>
		<view class="public-no-img" v-if="orderList.length==0">
			<image :src="getStaticFilePath('/QXY/noCollection.png')" mode=""></image>
		</view>
		<veiw class="send-li" v-for="(item,index) in orderList" :key="index" @click="goAndSee(item)">
			<view class="send-li-img">
				<image :src="item.SETTB99CA03|| getStaticFilePath('home/nav/noerpimg.png')"></image>
			</view>
			<view class="send-li-content">
				<view class="send-li-content-title">
					<text>{{item.SETTB99CA00}}</text>
					<text style="color: red;">{{item.mdj||''}}</text>
				</view>
				<view class="send-li-content-city">
					<text class="iconfont iconweizhi"></text>
					{{item.SETTB99CA02||'暂无地址'}}
				</view>
				<view class="send-li-content-bottom">
					<!-- <view class="send-li-content-collection" @click="collCancelClick(item)" v-if="item.SETTB403ID!=''">
						<text class="iconfont iconshoucang"></text>取消收藏
					</view> -->
					<view class="send-li-content-collection" v-if="item.SETTB403ID==''" @click="collClick(item)">
						<text class="iconfont iconshoucangqiye"></text>收藏
					</view>
					<view class="send-li-content-collection" style="color:#f60" v-else>已收藏</view>
					<!-- <view class="send-li-content-bottom-btn" @click="goAndSee(item)">
						<button type="default">去看看</button>
					</view> -->
				</view>
			</view>
		</veiw>
		<u-loadmore v-if="orderList.length!=0" :status="status" :icon-type="iconType" :load-text="loadText" />
		<u-toast ref="uToast" />
		<u-modal v-model="collShow" :content="collShowContent" :show-cancel-button="true" @confirm="collConfirm">
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: JSON.parse(uni.getStorageSync('userinfo')),
				orderList: [],
				page: 1,
				pageSize:10,
				countpage: '',
				erpkeyword: '',
				systemInfo: uni.getSystemInfoSync(),
				navHeight: '',
				optionHeight: 38,
				status: 'loading',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				cityCode: '',
				address: '',
				collShow: false,
				SETTB99ID: '',
				collShowContent: '',
				platform: false
			}
		},
		onLoad() {
			// this.getOrderList()
		},
		onShow() {
			this.platform = uni.getStorageSync('platform')
			this.systemInfo = uni.getSystemInfoSync()
			this.navHeight = this.systemInfo.platform == 'ios' ? 44 : 48;
			if (uni.getStorageSync('city')) {
				this.address = JSON.parse(uni.getStorageSync('city'))
			}
			this.cityCode = this.address.CODETB01CA00
			console.log(this.cityCode)
			this.getOrderList(this.cityCode)
		},
		onReachBottom() {
			if (this.page == this.countpage) {
				return this.status = "nomore"
			}

			this.page++
			this.getOrderList()
		},
		methods: {
			returnclick() {
				uni.reLaunch({
					url: '/pages/tabbar/home/index'
				})
			},
			goAndSee(item) {
				uni.setStorageSync('erpinfo', JSON.stringify(item));
				uni.setStorageSync('Erptype', 1);
				uni.navigateTo({
					url: '/pages/SOMater/index'
				})
			},
			erpIpt() {
				this.orderList = []
				this.page = 1
				this.countpage = 1
				this.getOrderList()
			},
			// 企业列表
			getOrderList() {
				uni.showLoading({
					title: '请求中...',
					mask: true
				});
				uni.request({
					url: this.baseUrl + '/set/settb99/selectPageList',
					method: 'POST',
					dataType: 'json',
					data: {
						SETTB403CA00: this.userinfo.PERTB005ID,
						ORMTB400ID: this.userinfo.ORMTB400ID, //一级客户ID
						SETTB99CA00: this.erpkeyword, //二级企业名称
						SETTB100CA04: this.cityCode, //市代码
						page: this.page,
						limit: 50,
					},
					success: (res) => {
						uni.hideLoading();
						console.log(res);
						if (res.data.code == 200) {
							if (!res.data.data || res.data.data == null) {
								this.orderList = []
								this.page = 1
								this.countpage = 1
								return
							}
							// var data = res.data.data || []
							if (this.page > 1) {
								this.orderList = [...this.orderList, ...res.data.data]
							} else {
								this.orderList = res.data.data
							}
							this.countpage = Math.ceil(res.data.count / 10)
						}

						else {
							this.orderList = []
							this.page = 1
							this.countpage = 1
							this.$refs.uToast.show({
								title: res.data.message,
								type: 'default',
								icon: false
							})
						}
						if (this.countpage == this.page) {
							this.status = "nomore"
						} else {
							this.status = "loadmore"
						}


					},
					fail: (res) => {
						if (this.countpage == this.page) {
							this.status = "nomore"
						} else {
							this.status = "loadmore"
						}
						uni.hideLoading();
						this.$refs.uToast.show({
							title: res.errMsg,
							type: 'default',
							icon: false
						})
					}
				});
			},
			//收藏
			collClick(item) {
				this.collShow = true
				this.SETTB99ID = item.SETTB99ID
				this.collShowContent = `请确认是否添加收藏:${item.SETTB99CA00}`
			},
			collConfirm() {
				uni.request({
					url: this.baseUrl + '/set/settb403/collect',
					method: 'POST',
					dataType: 'json',
					data: {
						PERTB005ID: this.userinfo.PERTB005ID, //用户ID
						SETTB99ID: this.SETTB99ID, //二级企业id
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							this.$refs.uToast.show({
								title: '收藏成功',
								type: 'default',
								icon: false
							})
							this.page = 1
							this.countpage = 1
							this.orderList = []
							this.getOrderList();
						} else {
							this.$refs.uToast.show({
								title: res.data.message,
								type: 'default',
								icon: false
							})
						}
					},
					fail: (res) => {
						this.$refs.uToast.show({
							title: res.errMsg,
							type: 'default',
							icon: false
						})
					}
				});
			},
			//取消收藏
			// collCancelClick(item){
			// 	uni.request({
			// 		url: this.baseUrl + '/set/settb403/delete',
			// 		method: 'POST',
			// 		dataType: 'json',
			// 		data: {
			// 			SETTB403CA00: this.userinfo.PERTB005ID, //用户ID
			// 			SETTB403ID: item.SETTB403ID, //收藏id
			// 		},
			// 		success: (res) => {
			// 			console.log(res);
			// 			if (res.data.code == 200) {
			// 				this.$refs.uToast.show({
			// 					title: '取消成功',
			// 					type: 'default',
			// 					icon:false
			// 				})
			// 				this.page = 1
			// 				this.countpage = 1
			// 				this.orderList = []
			// 				this.getOrderList();
			// 			} else {
			// 				this.$refs.uToast.show({
			// 					title: res.data.message,
			// 					type: 'default',
			// 					icon:false
			// 				})
			// 			}
			// 		},
			// 		fail: (res) => {
			// 			this.$refs.uToast.show({
			// 				title: res.errMsg,
			// 				type: 'default',
			// 				icon:false
			// 			})
			// 		}
			// 	});
			// },
		}
	}
</script>

<style>
	.send {
		min-height: 100vh;
		width: 100vw;
		background-color: #efeff4;
	}

	.send-nav-search {
		display: flex;
		margin: 1.5px 0;
	}

	.send-nav-search-ipt {
		flex: 1;
		background-color: #E3E3E3;
		margin-left: 30rpx;
		border-radius: 50rpx;
		padding-left: 20rpx;
	}

	.send-nav-search-ipt text {
		display: inline-block;
		height: 35px;
		line-height: 35px;
		vertical-align: top;
	}

	.send-nav-search-ipt input {
		display: inline-block;
		width: 90%;
		height: 35px;
		line-height: 35px;
		padding-left: 10rpx;
	}

	.send-nav-search-btn {
		width: 135rpx;
		height: 35px;
		line-height: 35px;
		text-align: center;
	}

	.send-nav-search-left-btn {
		width: 80rpx;
		height: 35px;
		line-height: 35px;
		text-align: center;
	}

	.send-image {
		height: 18vh;
		padding: 20rpx 30rpx;
		background-color: #fff;
	}

	.send-image image {
		width: 100%;
		height: 100%;
	}

	.send-title {
		height: 80rpx;
		line-height: 80rpx;
		background-color: #fff;
		box-sizing: border-box;
	}

	.send-title text {
		vertical-align: top;
	}

	.send-title-border {
		display: inline-block;
		width: 10rpx;
		height: 35rpx;
		margin: 22rpx 20rpx 22rpx 30rpx;
		background-color: #00a1f1;
		border-radius: 5rpx;
	}

	.send-li {
		display: flex;
		background-color: #fff;
		padding: 30rpx;
		border-bottom: 2rpx solid rgba(230, 230, 230, 0.5);
	}

	.send-li-img {
		width: 150rpx;
		height: 150rpx;
		margin-right: 20rpx;
		border-radius: 10rpx;
	}

	.send-li-img image {
		width: 100%;
		height: 100%;
		border-radius: 10rpx;
	}

	.send-li-content {
		flex: 1;
	}

	.send-li-content-title {
		display: flex;
		justify-content: space-between;
		color: #333;
		font-size: 36rpx;
		font-weight: 600;
	}

	.send-li-content-title text:first-child {
		/* height: 40rpx; */
		overflow: hidden;
		margin-right: 20rpx;
	}

	.send-li-content-title .iconarrow_right {
		color: #999;
	}

	.send-li-content-city .iconweizhi {
		font-size: 22rpx;
		color: #666;
		margin-right: 10rpx;
	}

	.send-li-content-city,
	.send-li-content-count {
		font-size: 32rpx;
		color: #999;
		/* height: 40rpx; */
		/* overflow: hidden; */
		padding: 10rpx 0;
	}

	.send-li-content-bottom {
		display: flex;
		justify-content: space-between;
	}

	.send-li-content-bottom-btn button {
		width: 130rpx;
		height: 50rpx;
		line-height: 50rpx;
		font-size: 20rpx;
		color: #FFF;
		background-color: #00a1f1;
	}

	.send-li-content-collection .iconshoucang {
		font-size: 30rpx;
		color: #f4ea2a;
		margin-right: 20rpx;
	}

	.send-li-content-collection .iconshoucangqiye {
		font-size: 30rpx;
		color: #999;
		margin-right: 20rpx;
	}

	.send-li-content-collection {
		height: 40rpx;
		color: #999;
		font-size: 28rpx;
	}

	.erp-serach {
		position: fixed;
		top: 0;
		width: 100%;
		display: flex;
		box-sizing: border-box;
		height: 85rpx;
		padding: 10rpx 0 0 0;
		background-color: #e3e3e3;
		z-index: 2;
	}

	.erp-serach-l {
		width: 120rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
	}

	.erp-serach-r {
		flex: 1;
	}

	.erp-serach-content {
		margin-top: 85rpx;
	}

	.erp-serach-content-li {
		display: flex;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 28rpx;
		color: #333;
		padding: 0 30rpx;
		overflow: hidden;
		border-bottom: 2rpx solid #e3e3e3;
	}

	.erp-serach-content {
		padding: 0 10rpx;
	}

	.erp-serach-content-li-text {
		flex: 1;
	}

	.erp-serach-content-li-ico .iconshoucangqiye {
		color: #999;
		font-size: 34rpx;
		margin-right: 10rpx;
	}

	.erp-serach-content-li-ico .iconshoucang {
		font-size: 30rpx;
		color: #f4ea2a;
		margin-right: 10rpx;
	}
</style>
